package com.zuoshenge.main.controller;

import com.zuoshenge.main.excel.export.CourseExcelExport;
import com.zuoshenge.main.excel.importt.CourseExcelImport;
import com.zuoshenge.main.excel.importt.listener.CourseExcelImportListener;
import com.zuoshenge.main.service.CourseService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("excel")
public class ExcelController {

    @Resource
    private CourseExcelImport courseExcelImport;
    @Resource
    private CourseExcelExport courseExcelExport;
    @Resource
    private CourseService courseService;

    @GetMapping("export-course")
    public void exportCourse(@RequestParam(value = "isEmptyExcel", required = false, defaultValue = "false") Boolean isEmptyExcel) {
        Map<String, Object> map = new HashMap<>();
        courseExcelExport.exportWithBigData("课程列表", map, isEmptyExcel);
    }

    @GetMapping("/import-course")
    public void testCourseExcelImport() {
        // TODO 把路径改为文件，sheet页数也要获取
        courseExcelImport.doImport("C:/Users/caojiarong/Desktop/课程列表 (35).xlsx",1,new CourseExcelImportListener(courseService));
    }
}
